package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.HealthRecord;
import com.noahplat.person.service.HealthRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: HealthRecordController
 * @Description: 体检报告controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/healthRecord")
@Validated
public class HealthRecordController {


    @Autowired
    private HealthRecordService healthRecordService;

    /**
     * 获取体检报告详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:HealthRecordController:getHealthRecord')")
    @GetMapping("/getHealthRecord")
    public Result getHealthRecord(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "ID不合法") Long id){
        return healthRecordService.getHealthRecord(id);
    }

    /**
     * 新增体检报告
     * @param healthRecord
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:HealthRecordController:addHealthRecord')")
    @PostMapping("/addHealthRecord")
    public Result addHealthRecord(@RequestBody HealthRecord healthRecord){
        return healthRecordService.addHealthRecord(healthRecord);
    }

    /**
     * 更新体检报告/删除体检报告
     * @param healthRecord
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:HealthRecordController:updateHealthRecord')")
    @PutMapping("/updateHealthRecord")
    public Result updateHealthRecord(@RequestBody HealthRecord healthRecord){
        return healthRecordService.updateHealthRecord(healthRecord);
    }

}
